<%--
 *  File:   SalesChannelTree.jsp
 *  Desc:	
 *
 *  Date		         Author		      Changes
 *  2006-3-7	  joshli		  Created
 *
 *  Copyright (C) 2000 - 2005 Oval Technologies, Inc.
 *  All rights reserved.
 *
 *  This software is the confidential and proprietary information of Oval
 *  Technologies, Inc. ("Confidential Information").  You shall not
 *  disclose such Confidential Information and shall use it only in
 *  accordance with the terms of the license agreement you entered into
 *  with Oval.
--%>

<%@ include file="/inc/SessionTimeout.inc"%>
<%@ page language="java" %>
<%@ page import="java.util.*" %>
<%@ page import="org.apache.log4j.Category" %>


<%@ page contentType = "text/html;charset=UTF-8" %>
<%@ taglib uri="/WEB-INF/PageFlow.tld" prefix="PageFlow" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/oval-tag.tld" prefix="oval" %>
<%@ taglib uri="/WEB-INF/custom.tld" prefix="custom" %>
<%
  //init param
  Category cat = Category.getInstance("jsp.SalesChannelTree");
  String privilegeCode = "Z0815";
  String strModuleName = "COM";
%>
<%
  //get curuserinfo
  HashMap CurUserInfo = (HashMap)session.getAttribute("userinfo");
  String strCurOrgName = (String)CurUserInfo.get("orgname");
  Integer nCurOrgId = (Integer)CurUserInfo.get("orgid");
  if(nCurOrgId == null)
  {
    nCurOrgId = new Integer(-1234567);
  }
	int grade = -1;
	if(CurUserInfo.get("grade") != null)
 	{
 	  grade = ((Integer)CurUserInfo.get("grade")).intValue();
 	}
%>
<%@ include file="/inc/Security.inc" %>
<%@ include file="/inc/PageDefault.inc" %>

<html>
<head>
<title></title>
<PageFlow:CheckPageFlow pageName="saleschanneltree"/>
<%
  Vector channels = (Vector)pageContext.getAttribute("channeltree");
  Integer nTreeOrgId = new Integer(-1);
  if(channels == null)
  {
    channels = new Vector();
  }
  cat.debug("The areas is :" + channels.size() + channels);
  OvalTree initTree = new OvalTree(channels,"saleschannelid","parentsaleschannelid","grade");
  initTree.setRecursiveLimit(2000);
  Vector channelTree = (Vector)initTree.getTreeVector(new Integer(-1000),1);
  cat.debug("The tree's size is :" + channelTree.size());
  cat.debug("The tree is :" + channelTree);
%>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="../../css/<%= strLanguageCode %>/main.css" type="text/css">
<SCRIPT language=JavaScript1.2 src="../../css/menu.js"></SCRIPT>
<script language="JavaScript" src="../../css/<%= strLanguageCode %>/script.js"></script>
<script language="JavaScript" src="../../js/FuncLib.js"></script>
<script language="JavaScript">
parent.rightFrame.location.href = "Blank.jsp?<%= OvalTools.randomURL() %>";
function page_view(id,grade,isbottom,parentid)
{
  document.channeltreeform.saleschannelid.value = id;
  document.channeltreeform.grade.value = grade;
  document.channeltreeform.isbottom.value = isbottom;
  document.channeltreeform.parentsaleschannelid.value = parentid;

  if(id == null || id.length == 0 || id == "" || id < 0)
  {
    return;
  }
  var viewchannel = "SalesChannelInfo.jsp?<%= OvalTools.randomURL() %>&saleschannelid=" + id + "&languagecode=" + "<%= strLanguageCode %>";
  parent.rightFrame.location.href = viewchannel;
}

function page_addnewchild()
{
  var id = document.channeltreeform.saleschannelid.value;
  if(id == null || id.length == 0 || id == "" || id < 0)
  {
    alert("<%= message.getMessageDesc("PLEASE_SELECT") %>");
    return;
  }
  var gradev = new Number(1) + new Number(document.channeltreeform.grade.value);
  var newchildurl = "SalesChannelEdit.jsp?<%= OvalTools.randomURL() %>&parentsaleschannelid=" + id + "&languagecode=" + "<%= strLanguageCode %>" + "&grade=" + gradev;
  parent.rightFrame.location.href = newchildurl;
}

function page_edit()
{
  var id = document.channeltreeform.saleschannelid.value;
  if(id == null || id.length == 0 || id == "" || id < 0)
  {
    alert("<%= message.getMessageDesc(" MUST_SELECT_ONE_RECORD_TO_EDIT") %>");
    return;
  }
  var editurl = "SalesChannelEdit.jsp?<%= OvalTools.randomURL() %>&saleschannelid=" + id + "&languagecode=" + "<%= strLanguageCode %>" ;
  parent.rightFrame.location.href = editurl;
}

function page_delete()
{
  var id = document.channeltreeform.saleschannelid.value;
  var isbottom = document.channeltreeform.isbottom.value;
  if(id == null || id.length == 0 || id == "" || id == "-1")
  {
    alert("<%= message.getMessageDesc("PLEASE_SELECT") %>");
    return;
  }
  if(!(isbottom == "Y" || isbottom == "y"))
  {
    alert("<%= message.getMessageDesc("NOT_LEAF",label.getLabelName("L_SalesChannelName",false)) %>");
    return;
  }
  var flag = confirm("<%= message.getMessageDesc("ARE_YOU_SURE_DEL") %>");
  if(!flag)
    return;
  document.channeltreeform.actionname.value = "delete";
  document.channeltreeform.target = "_parent";
  isRunning = true;
  document.channeltreeform.submit();
}
</script>
</head>

<body>

<table width="100%" border="0" cellspacing="0" cellpadding="0" height="100%">
  <form name="channeltreeform" method="post" action="../../Dispatcher">
       <input type="hidden" name="pagename" value="saleschanneltree">
       <input type="hidden" name="actionname">

       <input type="hidden" name="saleschannelid">
       <input type="hidden" name="isbottom">
       <input type="hidden" name="grade">
       <input type="hidden" name="parentsaleschannelid">
   <tr>
    <td valign="top">
      <table width="100%" border="0" cellpadding="0" cellspacing="0">
        <tr>
          <td class="summary_top"></td>
        </tr>
      </table>
      <table width="100%" border="1" cellpadding="0" bordercolorlight="#999999" bordercolordark="#FFFFFF" cellspacing="0" align="center" height="86%">
        <tr>
          <td colspan="-1" class="deepblue-left"><img src="../../images/<%= strLanguageCode %>/quote.gif" width="16" height="11">
            <%= label.getLabelName("L_SalesChannelName") + label.getLabelName("L_Colon") %></td>
        </tr>
        <tr>
          <td class="spe-td">
		  <div id=div2 style="OVERFLOW: scroll; WIDTH: 234px; HEIGHT: 465px">
       <%
   if(channelTree.size() != 0)
   {
     int nTreeLevel = 0;
     int nLevelDif = 0;
     int nTopLevel = 0;
     int nEndLevel = 0;
     String strIMG = "TreeAdd.gif";
     for(int i = 0;i < channelTree.size();i++)
     {
       HashMap temp = (HashMap)channelTree.elementAt(i);
       cat.debug("Now the temp is:" + temp);
       nTreeOrgId = (Integer)temp.get("orgid");
       int nNext = ((Integer)temp.get("next")).intValue();
       String strLevelCode = (String)temp.get("levelcode");
       nTreeLevel = ((Integer)temp.get("grade")).intValue()+ nLevelDif;
       if(((Boolean)temp.get("ismin")).booleanValue())
       {
         strIMG = "TreeSub.gif";
       }
       else
       {
         strIMG = "TreeAdd.gif";
       }
       for(int j = 0;j <= -nNext;j++)
       {
         if(i != 0)
         {
   %>
   </div>
           </td>
          </tr>
         </table>
         <%
         }
       }

       if(((Boolean)temp.get("ismax")).booleanValue())
       {
         nTopLevel = ((Integer)temp.get("grade")).intValue();
         nTreeLevel = 1;
         nLevelDif = ((Integer)temp.get("grade")).intValue() - 1;
   %>
   <table cellspacing="0" width="100%">
       <tr>
        <td class="TreeClass1"><a href="javascript:void(0)" <%if(!((Boolean)temp.get("ismin")).booleanValue()){%>onClick="expandIt(channeltreeform,'KB<%=JspHelper.filterNull( strLevelCode )%>','../../images/<%= strLanguageCode %>/'); return false"<%}%>><img name="KB<%=JspHelper.filterNull( strLevelCode )%>wj" src="../../images/<%= strLanguageCode %>/<%=JspHelper.filterNull( strIMG )%>" height="11" border="0" ></a><a href="javascript:page_view('<%=JspHelper.filterNull( temp.get("saleschannelid") )%>','<%=JspHelper.filterNull( temp.get("grade") )%>','<%=JspHelper.filterNull( temp.get("isbottom") )%>','<%=JspHelper.filterNull( temp.get("parentsaleschannelid") )%>')"><%=JspHelper.filterNull( temp.get("saleschannelname"))%></a>
         <div class=child<%=JspHelper.filterNull( strLevelCode )%> id=KB<%=JspHelper.filterNull( strLevelCode )%>Child>
    <%
       }
       if(!((Boolean)temp.get("ismax")).booleanValue() && !((Boolean)temp.get("ismin")).booleanValue())
       {
   %>
   <table cellspacing="0" width="100%">
           <tr>
            <td class="TreeClass<%=JspHelper.filterNull( nTreeLevel )%>"><a href="#" onClick="expandIt(channeltreeform,'KB<%=JspHelper.filterNull( strLevelCode )%>','../../images/<%= strLanguageCode %>/'); return false"><img src="../../images/<%= strLanguageCode %>/<%=JspHelper.filterNull( strIMG )%>" width="11" height="11" name="KB<%=JspHelper.filterNull( strLevelCode )%>wj" border="0"></a><a href="javascript:page_view('<%=JspHelper.filterNull( temp.get("saleschannelid") )%>','<%=JspHelper.filterNull( temp.get("grade") )%>','<%=JspHelper.filterNull( temp.get("isbottom") )%>','<%=JspHelper.filterNull( temp.get("parentsaleschannelid") )%>')"><%=JspHelper.filterNull( temp.get("saleschannelname"))%></a>
            <div class=child<%=JspHelper.filterNull( strLevelCode )%> id=KB<%=JspHelper.filterNull( strLevelCode )%>Child>
   <%
       }
       if(!((Boolean)temp.get("ismax")).booleanValue() && ((Boolean)temp.get("ismin")).booleanValue())
       {
   %>
   <table cellspacing="0" width="100%">
           <tr>
            <td class="TreeClass<%=JspHelper.filterNull( nTreeLevel )%>"><a href="javascript:void(0)"><img src="../../images/<%= strLanguageCode %>/<%=JspHelper.filterNull( strIMG )%>" width="11" height="11" name="KB<%=JspHelper.filterNull( strLevelCode )%>wj" border="0"></a><a href="javascript:page_view('<%=JspHelper.filterNull( temp.get("saleschannelid") )%>','<%=JspHelper.filterNull( temp.get("grade") )%>','<%=JspHelper.filterNull( temp.get("isbottom") )%>','<%=JspHelper.filterNull( temp.get("parentsaleschannelid") )%>')"><%=JspHelper.filterNull( temp.get("saleschannelname"))%></a>
             <div>
    <%
       }
       nEndLevel = ((Integer)temp.get("grade")).intValue();
     }
     //close the tag
     for(int h = 0; h <= nEndLevel - nTopLevel;h++)
     {
   %>
              </div>
             </td>
            </tr>
           </table>
   <%
     }
   }
   %>
      </div>
          </td>
        </tr>
        <tr>
          <td class="td-listrom">&nbsp;</td>
        </tr>
      </table>
      <table border="0" cellspacing="1" width="100%">
        <%
          if(nCurOrgId.equals(nTreeOrgId) || nTreeOrgId.intValue() == -1 && grade == 1)
          {
        %>
        <tr>
          <td class="td_center"><a onclick="parent.rightFrame.location.href='SalesChannelEdit.jsp?<%= OvalTools.randomURL() %>';"><custom:button type="1" label="L_New" imgsrc="new.gif" border="0" style="width:60"/></a>
          <a onclick="page_edit()"><custom:button type="1" label="L_Edit" imgsrc="edit.gif" border="0" style="width:60"/></a>
          <a onclick="page_delete()"><custom:button type="1" label="L_Delete" imgsrc="delete.gif" border="0" style="width:60"/></a></td>
        </tr>
        <tr>
          <td class="td_center"><a onclick="page_addnewchild()"><custom:button type="1" label="L_CreatSubChannel" imgsrc="CreatSubArea.gif" border="0"/></a></td>
        </tr>
        <%
          }
        %>
      </table>
    </td>
  </tr>
    </form>
</table>

 </body>
<script language="JavaScript">
  var ht = document.body.clientHeight - 100;
  if(ht < 0 )
    ht = 0;
  div2.style.height= ht;
</script>
    <SCRIPT language=JavaScript1.2>initIt(channeltreeform,'../../images/<%= strLanguageCode %>/');</SCRIPT>
</html>
